﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows;
using DocumentManagement.Models;
using System.Windows.Data;

namespace DocumentManagement.ViewsModels
{
   public class ReportDocumentOutDateViewsModel : ViewsModelBase
    {
         public QSHCEntities1 _entityModels;
        public QSHCEntities1 EntityModels
        {
            get { return _entityModels; }
            set
            {
                if (_entityModels != value)
                {
                    _entityModels = value;
                    OnPropertyChanged("EntityModels");
                }
            }
        }

        public ICollectionView _mySendICV;
        public ICollectionView MySendICV
        {
            get { return _mySendICV; }
            set
            {
                if (_mySendICV != value)
                {
                    _mySendICV = value;
                    OnPropertyChanged("MySendICV");
                }
            }
        }

        private int _myText1;
        public int MyText1
        {
            get { return _myText1; }
            set
            {
                if (_myText1 != value)
                {
                    _myText1 = value;
                    OnPropertyChanged("MyText1");
                }
            }
        }
        private int _myText2;
        public int MyText2
        {
            get { return _myText2; }
            set
            {
                if (_myText2 != value)
                {
                    _myText2 = value;
                    OnPropertyChanged("MyText2");
                }
            }
        }
        private int _myText3;
        public int MyText3
        {
            get { return _myText3; }
            set
            {
                if (_myText3 != value)
                {
                    _myText3 = value;
                    OnPropertyChanged("MyText3");
                }
            }
        }

        private DateTime? _myDateDocInFromOUT;
        public DateTime? MyDateDocInFromOUT
        {
            get { return _myDateDocInFromOUT; }
            set
            {
                if (_myDateDocInFromOUT != value)
                {
                    _myDateDocInFromOUT = value;
                    OnPropertyChanged("MyDateDocInFromOUT");
                }
            }
        }
        private DateTime? _myDateDocInToOUT;
        public DateTime? MyDateDocInToOUT
        {
            get { return _myDateDocInToOUT; }
            set
            {
                if (_myDateDocInToOUT != value)
                {
                    _myDateDocInToOUT = value;
                    OnPropertyChanged("MyDateDocInToOUT");
                }
            }
        }

        public ReportDocumentOutDateViewsModel()
        {
            if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                EntityModels = new QSHCEntities1();

            }

         
        }

        public void CheckDateReportOUT() //DateTime? MyDateDocInFrom, DateTime? MyDateDocInTo
        {
            //.ToList().Where(p => p.ReceiveDate >= MyDateDocInFrom.Value.Date).ToList().Where(p => p.ReceiveDate <= MyDateDocInTo.Value.Date).ToList()
            //MessageBox.Show(MyDateDocInFrom.Value.Date.ToString());
            MySendICV = CollectionViewSource.GetDefaultView(EntityModels.CreateSends.Where(p => p.Active == true).ToList()); //.Where(p => p.Active == true)
            MySendICV.Filter += (o) =>
            {
                CreateSend p = (o as CreateSend);

                if (p == null)

                    return false;

                if (MyDateDocInFromOUT.Value.Date != null && MyDateDocInToOUT.Value.Date != null)
                {

                    if ((p.CreateSendDate.Date >= MyDateDocInFromOUT.Value.Date) && p.CreateSendDate.Date <= MyDateDocInToOUT.Value.Date)
                        return true;
                    else
                        return false;

                }

                return true;

            };

            
            //MyText1 = EntityModels.Sends.Count(p => p.Active == true);
            //MyText2 = EntityModels.Sends.Where(p => p.Active == true).Where(p => p.Status == 1).Where(p => p.SendDate >= MyDateDocInFromOUT.Value.Date).Where(p => p.SendDate <= MyDateDocInToOUT.Value.Date).ToList().Count();
            ////MyText2 = EntityModels.Sends.Count(p => p.Active == true) && EntityModels.Sends.Count(p => p.Status == 1);
            //MyText3 = EntityModels.Sends.Count(p => p.Status == 2);

        }


    }
}
